<!-- 项目经济运营分析会 -->
<template>
    <base-breadcrumb>
        <searchData :searchData="searchArr" @search="search"></searchData>
        <a-card>
            <!-- <div class="table-operator">
                <a-button v-btnPermission="'bm_012_add_01'" type="primary" icon="plus" @click="handleUpdate('add', {})">新增会议</a-button>
            </div> -->
            <list-table
                ref="table"
                size="default"
                rowKey="id"
                :columns="columns"
                :request="loadData"
                :alert="true"
                show-size-changer
                show-quick-jumper
                showPagination="auto"
                :export-config="{
                        use: true,
                        select: '项目经济运营分析会',
                        all: '项目经济运营分析会'
                    }"
                :exportPermission="{ select: 'bm_012_exp_01', all: 'bm_012_exp_01' }"
                :statistics-config="{ use: true, total, temp }"
            >
                <span slot="operation" slot-scope="text, record">
                    <MoreButton>
                    <a @click="handleUpdate('start', record)" v-if="record.status == 20" v-btnPermission="'bm_012_loo_03'">查看会议</a>
                    <a @click="handleUpdate('newEdit', record)"  v-btnPermission="'bm_012_edi_02'" v-if="record.status == 10">编辑</a>
                    <a @click="handleUpdate('edit', record)" v-if="record.status == 30" v-btnPermission="'bm_012_edi_02'">进入会议</a>
                    <a @click="handleUpdate('look', record)" v-if="record.status == 40" v-btnPermission="'bm_012_loo_03'">查看会议</a>
                    </MoreButton>
                   
                </span>
                <span slot="commentedPlan" slot-scope="text, record">
                    {{ record.meetingExtraVO.commentedPlan }}
                </span>
                <span slot="professionComName" slot-scope="text, record">
                    {{ record.meetingExtraVO.professionComName }}
                </span>
                <span slot="avgScore" slot-scope="text, record">
                    {{ record.meetingExtraVO.avgScore }}
                </span>

                <span slot="status" slot-scope="text, record">
                    <list-status :status="record.status" conversion="en" :text="text"></list-status>
                </span>
            </list-table>
        </a-card>
    </base-breadcrumb>
</template>
<script>
import SelectSubCompany from '@/components/Select/SelectSubCompany' // 分公司
import SelectProject from '@/components/Select/SelectProject' // 项目
import OrgTreeSelect from '@/components/OrgTreeSelect'
import SelectSubcontractor from '@/components/Select/SelectSubcontractor' // 分包商
import { STable } from '@/components'
import listStatus from '@/components/list_status/meeting_status'
import { getMeetingList, startMeeting, getSearchList, getCountList } from '@/api/office/conference'

const columns = [
        {
        title: '序号',
        width: 80,
        dataIndex: 'index',
        customRender() {
            return arguments[2] + 1
        },
    },

    {
        title: '会议名称',
        dataIndex: 'meetingName',
    },
      {
        title: '月份',
        dataIndex: 'month',
    },
    {
        title: '所属分公司',
        dataIndex: 'branchComName',
    },
    {
        title: '所属项目',
        dataIndex: 'projectName',
    },
    {
        title: '召开时间',
        dataIndex: 'startTime',
    },
    {
        title: '参会人数',
        dataIndex: 'meetingCount',
    },
    {
        title: '状态',
        dataIndex: 'statusSer',
        // scopedSlots: { customRender: 'status' },
    },
    {
        title: '操作',
        dataIndex: 'operation',
        width: '170px',
        scopedSlots: { customRender: 'operation' },
    },
]
const searchArr = [
  {
    name: '所属单位',
    valueKey: 'searchQuery',
    type: OrgTreeSelect,
  },
    // {
    //     name: '所属分公司',
    //     valueKey: 'branchComId',
    //     type: SelectSubCompany,
    // },
    // {
    //     name: '所属项目',
    //     keyValue: 'branchComId',
    //     valueKey: 'projectId',
    //     type: SelectProject,
    // },
    {
        name: '会议名称',
        value: 'meetingName',
        type: 'input',
    },
    {
        name: '召开时间',
        value: 'startEndDate',
        type: 'dateRange',
    },
    {
        name: '状态',
        value: 'status',
        type: 'select',
        data: [
            {
                value: '10',
                label: '待提交',
            },
            {
                value: '20',
                label: '待开始',
            },
            {
                value: '30',
                label: '进行中',
            },
            {
                value: '35',
                label: '审批中',
            },
            {
                value: '40',
                label: '已完结',
            },
        ],
    },
        {
        name: '月份',
        type: 'month',
        value: 'month',
        attrs: {
            valueFormat: 'YYYY-MM'
        }
    },
]
export default {
    name:'a'+Date.now(),
    components: {
        STable,
        listStatus,
    },
    data() {
        this.columns = columns
        this.searchArr = searchArr
        return {
            countList:{},
            total:{},
            queryParam: {},
            temp: () => {
            return (
                <span style="margin-right: 12px">
                待提交：<span class="totalNum">{this.countList.draftCount }  </span> 
                待开始：<span class="totalNum">{this.countList.waitStartCount }  </span>
                进行中：<span class="totalNum">{this.countList.inProgressCount }</span>
                已完结：<span class="totalNum">{this.countList.endCount }  </span>  
                </span>
            )
          },
            loadData: async (parameter) => {
                this.queryParam.query = { ...this.queryParam.query, typeId: 4 }
                const requestParameters = Object.assign({}, parameter, this.queryParam)
                this.getCountList(requestParameters)
                const [err, res] = await getMeetingList(requestParameters)
                return new Promise((resolve, reject) => {
                    if (err) {
                        reject(err)
                    } else {
                        resolve(res)
                    }
                })
            },
        }
    },
    mounted() {
        // this.getSearchListReq()
    },
    methods: {
        getCountList(requestParameters){
            getCountList(requestParameters).then(resp=>{
                const [err, res] = resp
            if (res.code === 200) {
                this.countList=res.data
              }
          })
        },
        // async getSearchListReq() {
        //     const [err, res] = await getSearchList({ typeId: 4 })
        //     if (!err) {
        //         res.data.forEach((item) => {
        //             item.value = item.id
        //             item.label = item.name
        //         })
        //         searchArr[2].data = res.data || []

        //     }
        //      this.searchArr = searchArr
        // },
        //搜索
        search(val = {}) {
            this.queryParam.query = {
                ...val,
                typeId: 4,

                startTime:
                    (val.startEndDate && val.startEndDate.length && val.startEndDate[0].format('YYYY-MM-DD')) || void 0,
                endTime:
                    (val.startEndDate && val.startEndDate.length && val.startEndDate[1].format('YYYY-MM-DD')) || void 0,
            }
            console.log(this.queryParam)

            this.$refs.table.refresh(true)
        },

        // 处理更新操作（新增、编辑）
        async handleUpdate(type, data = {}) {
            if (type == 'del') {
                // const [err, res] = await deleteEquipment({ id: data.id })
                // if (!err) {
                //     this.$message.success('成功')
                //     this.$refs.table.refresh(true)
                // }
            }
            // else if (type == 'start') {
            //     const [err, res] = await startMeeting({ id: data.id })
            //     if (!err) {
            //         this.$message.success('成功')
            //         this.$refs.table.refresh(true)
            //     }
            // }
            else if (type == 'edit' || type == 'look' || type == 'start') {
                this.$router.push({
                    name: 'businessAnalysisInputSummary',
                    query: {
                        id: data.id || '',
                        pageType: type,
                    },
                })
            } else {
                this.$router.push({
                    name: 'businessAnalysisMeetingListEdit',
                    query: {
                        id: data.id || '',
                        pageType: type,
                        typeId: 4,
                    },
                })
            }
        },
    },
}
</script>
